#ifndef SCENENODE_H
#define SCENENODE_H

#include <d3d9.h>
#include <d3dx9.h>
#include <vector>

class Device;

class SceneNode {
public:
  SceneNode();
  SceneNode(const SceneNode * rhs);
  virtual ~SceneNode() {};
  void destroyGraph();
 
  //only to be called in main thread
  virtual long preDraw(Device * device){return 0;};
  virtual long passDraw(Device * device, unsigned long i){return 0;};
  virtual long postDraw(Device * device){return 0;};
  long drawScene(Device * device);

  //only to be called in app thread
  virtual SceneNode * copy() const;    // create a new copy
  SceneNode * copyGraph() const;       // recursive copy of entire graph
  void addChild(SceneNode * child);    // add an existing node as a child
  void removeChild(SceneNode * child); // remove node as a child
  void removeAll();                    // remove all children
  void destroyChildren();              // destroy all nodes below this one in the graph

  SceneNode * getChild(unsigned long index) const;
  unsigned long childCount() const {return (unsigned long)_children.size();};

  virtual SceneNode * select(const D3DXVECTOR4 & v); // used for mouse selection

protected:
  unsigned long _passes;

private:
  std::vector<SceneNode *> _children;
  SceneNode * _parent;
};

class TextureNode : public SceneNode{
public:
  TextureNode();
  TextureNode(unsigned long color, LPDIRECT3DTEXTURE9 texture):color(color),texture(texture){};
  TextureNode(const TextureNode * rhs);

  long preDraw(Device * device);
  virtual long postDraw(Device * device);
  SceneNode * copy() const;

  unsigned long color;
  LPDIRECT3DTEXTURE9 texture;

private:
  unsigned long _prev_color;
  LPDIRECT3DTEXTURE9 _prev_texture;
};

#endif
